package com.day0928.polymorphic;

import java.util.concurrent.Callable;

public class Master {
//    public Dog getDog(){
//        Dog dog =  new Dog("花花",100,100,"二哈");
//        return dog;
//    }
//    public Penguin getPenguin(){
//        Penguin penguin = new Penguin("草草",100,100,"女");
//        return penguin;
//    }
//    public Cat getCat(){
//        Cat cat = new Cat("猫猫",100,100,"喝奶");
//        return cat;
//    }

    //  多态   Pet pet = new Dog();
    //  工厂设计模式
     public Pet getPet(String type){
        if (type.equals("Dog")){
            Dog dog =  new Dog("花花",100,100,"二哈");
            return dog;
        }else if (type.equals("Penguin")){
            Penguin penguin = new Penguin("草草",100,100,"女");
            return penguin;
        }else if (type.equals("Cat")){
            Cat cat = new Cat("猫猫",100,100,"喝奶");
            return cat;
        }
        return null;
     }

     public void feet(Pet pet){
         pet.eat();
     }

     public void cure(Pet pet){
         pet.toHospotial();
     }

     public void play(Pet pet){
         //  强制转换 === 向下转型
         //  自动类型转换 === 向上转型
         //  判断类型 判断Pet具体什么类型
         if (pet instanceof Dog){   //  对象 instanceof  类型   判断一个对象是否是某种类型
             Dog dog = (Dog)pet;
             dog.jiefeipan();
         }
         if (pet instanceof Penguin){
             Penguin penguin = (Penguin)pet;
             penguin.swimming();
         }
         if (pet instanceof Cat){
            Cat cat = (Cat)pet;
             cat.lumao();
         }
//         Pet pet1 = new Penguin("草草",100,100,"女");
//         ((Penguin) pet1).swimming();
     }
}
